//2009/09/08 21:12:47
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Spamatronic
{
public:
    vector <int> filter(vector <string> knownSpam, vector <string> newMail)
    {
        set<string> spam;
        set<string>::iterator it;
        for (int i=0; i<knownSpam.size(); i++)
        {
            int idx = 0;
            string s;
            s.clear();
            while (idx < knownSpam[i].size())
            {
                if (isalpha(knownSpam[i][idx])) s += tolower(knownSpam[i][idx]);
                else
                {
                    if (s.size() > 0) spam.insert(s);
                    s.clear();
                }
                idx ++;
            }
            if (s.size() > 0) spam.insert(s);
        }
        //for(it=spam.begin(); it!=spam.end(); it++) cout << (*it) <<", ";
        //cout << endl;
        vector<int> ret;
        for (int i=0; i<newMail.size(); i++)
        {
            int score = 0;
            int total = 0;
            int idx = 0;
            string s;
            s.clear();
            vector<string> str;
            str.clear();
            while (idx < newMail[i].size())
            {
                if (isalpha(newMail[i][idx])) s += tolower(newMail[i][idx]);
                else
                {
                    if (spam.count(s) > 0) score ++;
                    if (s.size() > 0)
                    {
                        total ++;
                        //spam.insert(s);
                        str.push_back(s);
                    }
                    s.clear();
                }
                idx ++;
            }
            if (spam.count(s) > 0) score ++;
            if (s.size() > 0) total ++;
            s.clear();
            //cout << "Score: " << score << " Total: " << total << endl;
            if (100.0 * score / total < 75.0)
                ret.push_back(i);
			else
				for (int j=0; j<str.size(); j++)
                    spam.insert(str[j]);
        }
        return ret;
    }
};
/*
 * Problem here:
 * In the same msg, there will be some words are same.
 * so, the total or score will be more than we need, sometimes.
 * Therefore, it's wrong.*/
